package top.shmly.universal.web.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.shmly.universal.base.common.Result;
import top.shmly.universal.base.response.IResponseResult;
import top.shmly.universal.base.response.ResponseResult;


import java.util.HashMap;
import java.util.Map;

/**
 * @program: universal
 * @description: test
 * @author: Jibny
 * @date 2021-04-27 09:24:37
 */
@Api(tags = "测试hello")
@RestController
@RequestMapping("/hello")
public class TestController {

    @Autowired
    private UserDetailsService userDetailsService;


    @ApiOperation(value = "测试", notes = "测试")
    @GetMapping("/test")
    public Result<Map> getTest(){
        IResponseResult<Map> iResponseResult = new ResponseResult<>();
        Map map = new HashMap();
        UserDetails userDetails = this.userDetailsService.loadUserByUsername("18012345678");
        UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
        SecurityContextHolder.getContext().setAuthentication(authentication);
        map.put("data", SecurityContextHolder.getContext().toString());
        return iResponseResult.ok(map);
    }

    @ApiOperation(value = "测试1", notes = "测试1")
    @GetMapping("/test1")
    public Result<Map> getTest1(){
        IResponseResult<Map> iResponseResult = new ResponseResult<>();
        return iResponseResult.ok("测试1111111111");
    }

}
